package com.gxa.service.goods.impl;

import com.gxa.dao.goods.GoodsMapper;
import com.gxa.dao.goods.GoodsOneTypeMapper;
import com.gxa.pojo.goods.Goods;
import com.gxa.pojo.goods.Goods1;
import com.gxa.pojo.goods.GoodsOneType;
import com.gxa.pojo.goods.GoodsPage;
import com.gxa.service.goods.GoodsOneTypeService;
import com.gxa.service.goods.GoodsService;
import com.gxa.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

public class GoodsServiceimpl implements GoodsService {
    SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();
    SqlSession sqlSession = sqlSessionFactory.openSession(true);
    GoodsMapper mapper = sqlSession.getMapper(GoodsMapper.class);


    @Override
    public List<Goods> selectAll() {
        List<Goods> goods = mapper.selectAll();
        return goods;
    }

    @Override
    public List<Goods> selectif(Goods goods) {
        List<Goods> selectif = mapper.selectif(goods);
        return selectif;
    }

    @Override
    public int insert(Goods goods) {
        int insertgoods = mapper.insertgoods(goods);
        sqlSession.commit();
        return insertgoods;
    }

    @Override
    public int insertgoddss(List<Goods> goods) {
        int insertgoddss = mapper.insertgoddss(goods);
        return insertgoddss;
    }

    @Override
    public int updata(Goods goods) {
        int updata = mapper.updata(goods);
        return updata;
    }

    @Override
    public int selectAllPage() {
        int i = mapper.selectallPage();
        return i;
    }

    @Override
    public List<Goods1> selectByPageAndif(int begin, int size, Goods goods) {
       int page =(begin-1)*size;
        String barcode = goods.getBarcode();
        if (barcode!=null && barcode!=""){
            goods.setBarcode("%"+barcode+"%");
        }
        String gname = goods.getGname();
        if (gname!=null && gname!=""){
            goods.setGname("%"+gname+"%");
        }
        List<Goods1> goods1 = mapper.selectByPage(page, size, goods);



        return goods1;
    }

    @Override
    public int updates(int gid, int state) {
        int updatas = mapper.updatas(gid, state);

        return updatas;
    }


}
